class Pgformatter < Formula
  desc "PostgreSQL syntax beautifier"
  homepage "https://sqlformat.darold.net/"
  url "https://github.com/darold/pgFormatter/archive/v4.4.tar.gz"
  sha256 "7db5451064425fb13ff86a723654dcedc6554b62cbf5777bc65f30ffbf833480"
  license "PostgreSQL"

  bottle do
    sha256 cellar: :any_skip_relocation, arm64_big_sur: "0b0e188f17ebdc9d493d450f3eff18f8c3de039f5dd7fa5fc9149f7ddc99a60b"
    sha256 cellar: :any_skip_relocation, big_sur:       "0e4436d5bcd6f06c948428e34b2afe1be57984d11aa5c8eed6161d76273f12ed"
    sha256 cellar: :any_skip_relocation, catalina:      "afcce813b73ebaa9326790850289abdfeba332e4be86c6e55fcec6220b66bbef"
    sha256 cellar: :any_skip_relocation, mojave:        "d991b9830807c92d78108a2320a358d162db5749b97bcdb8dea846058392c97c"
    sha256 cellar: :any_skip_relocation, high_sierra:   "86e00ee2a7f917e6e0e8c7409c788267faeb710b4c707f4a6463bcd0c2dd0fae"
    sha256 cellar: :any_skip_relocation, x86_64_linux:  "960ae2e48b850cc0292fad3b3fe88bcb657f48c7629f2eacd673127f90a348fb"
  end

  def install
    system "perl", "Makefile.PL", "DESTDIR=."
    system "make", "install"

    unless OS.mac?
      mkdir "usr/local/share"
      mv "usr/local/man", "usr/local/share"
    end
    prefix.install (buildpath/"usr/local").children
    (libexec/"lib").install "blib/lib/pgFormatter"
    libexec.install bin/"pg_format"
    bin.install_symlink libexec/"pg_format"
  end

  test do
    test_file = (testpath/"test.sql")
    test_file.write("SELECT * FROM foo")
    system "#{bin}/pg_format", test_file
  end
end
